package handler

import (
	"github.com/name5566/leaf/gate"
	"server/game/vehicle"
	"server/msg/jsonData"
)

func NewVehicle(args []interface{}) {
	m := args[0].(*jsonData.MsgNewVehicleReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	ret, err := vehicle.NewVehicle(m.UserId, m.VtId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret})
}
func VehicleList(args []interface{}) {
	m := args[0].(*jsonData.MsgVehicleListReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	ret, err := vehicle.VehicleList(m.UserId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret})
}
func VehicleInfo(args []interface{}) {
	m := args[0].(*jsonData.MsgVehicleInfoReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	ret, err := vehicle.VehicleInfo(m.UserId, m.VtId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret, RequestId: m.RequestId})
}
func UpdateVehicleLevel(args []interface{}) {
	m := args[0].(*jsonData.MsgUpVehicleUpLevelReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	ret, err := vehicle.UpdateVehicleLevel(m.UserId, m.VtId, m.Step)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret, RequestId: m.RequestId})
}
func UnLockVehicleSkillInfo(args []interface{}) {
	m := args[0].(*jsonData.MsgUnlockVehicleSkillReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	ret, err := vehicle.UnLockVehicleSkillInfo(m.UserId, m.VtId, m.SkillId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret, RequestId: m.RequestId})
}
func VehicleSkillRandNum(args []interface{}) {
	m := args[0].(*jsonData.MsgVehicleRandNumReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	ret, err := vehicle.VehicleSkillRandNum(m.UserId, m.VtId, m.SkillId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret, RequestId: m.RequestId})
}
func UpVehicleSkillLevel(args []interface{}) {
	m := args[0].(*jsonData.MsgUpVehicleSkillLevelReq)
	// 消息的发送者
	a := args[1].(gate.Agent)
	ret, err := vehicle.UpVehicleSkillLevel(m.UserId, m.VtId, m.SkillId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret, RequestId: m.RequestId})
}
